home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Shared / MM / Scripts / CMN / form.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  2.4 KB  |  104 lines

  1. //
  2. // Copyright 1999 Macromedia, Inc. All rights reserved.
  3. //
  4. //form.js
  5. //
  6. //Add a form around a given text string if a form does
  7. //not alreay exist in the current document or layer
  8. //
  9. //--------------------------------------------------------------
  10. //   
  11. //IPIsInsideOfForm(){
  12. //isLayer(obj){
  13. //checkForFormTag(formItemStr){
  14.  
  15.  
  16. //function: checkForFormTag
  17. //description: given a text string, wraps form tags around it
  18. //if there is not already a form in the current document or layer
  19. function checkForFormTag(formItemStr){
  20.    var uniqueFormName;
  21.    var retVal = formItemStr;
  22.    
  23.    if ( !IPIsInsideOfForm()  ){
  24.       uniqueFormName = createUniqueName("FORM","form");
  25.       retVal = '<FORM name="'+ uniqueFormName + '">' + formItemStr + '</form>';   
  26.    }
  27.  
  28.    return retVal;
  29. }
  30.  
  31.  
  32. //function: IPisInsideOfForm
  33. //description: determines if the cursor is inside of a form
  34. //             If the selected object is inside of a layer,
  35. //             does not search past the layer, because
  36. //            forms must be inside of layers in Netscape.        
  37. //returns: boolean
  38.  
  39. function IPIsInsideOfForm(){
  40.    var isInsideOfForm = false;
  41.    var objName;
  42.    
  43.    //get selected object
  44.    var selObj = getSelectedObj();
  45.    
  46.    //climb up the tree, and look for a form tag
  47.    //if a layer, html, or body tag is found, then stop looking
  48.    //and return false
  49.    while ( selObj ){
  50.       
  51.       //if the tag doesn't have a name (text or comments), climb up the tree
  52.       if (!selObj.tagName){
  53.          selObj = selObj.parentNode;
  54.          continue;
  55.       }
  56.         objName = selObj.tagName;
  57.         
  58.       //if its a form, return true
  59.       if (objName == "FORM"){
  60.          isInsideOfForm = true;
  61.          break;
  62.       }
  63.       
  64.       //if we hit a body, html, or layer tag, return false
  65.       if (  isLayer(selObj) || objName == "BODY" || objName.tagName == "HTML")
  66.          break;
  67.        
  68.       //climb up the tree...
  69.       selObj = selObj.parentNode;
  70.    }
  71.  
  72.    return isInsideOfForm;
  73. }
  74.  
  75.  
  76. //function: isLayer
  77. //description: given an object, determines whether it is a layer
  78.  
  79. function isLayer(obj){
  80.  
  81.    var isLayer = false;
  82.    var objName = obj.tagName.toLowerCase();
  83.    var pattern;
  84.    
  85.    switch (objName){
  86.       case "layer":
  87.       case "ilayer":
  88.          isLayer = true;
  89.          break;
  90.          
  91.       case "span":
  92.       case "div":
  93.          pattern = /position[\W]*[:][\W]*absolute/i;
  94.          if (   obj.style && pattern.exec(obj.style)!= null  )
  95.             isLayer = true;
  96.          break;
  97.          
  98.       default:
  99.          break;  
  100.   }
  101.   return isLayer;
  102. }
  103.  
  104.